<interface>
  <bindings>
    <!-- Variables for aftertouch translation to mod wheel- 
         for Mercury's setup -->
    <declare var="VAR_midi_modwheel" type="int" init="1"/>
    <declare var="VAR_midi_modwheel_val" type="int" init="0"/>
    <declare var="VAR_midi_channelpressure" type="int" init="0"/>

    <!-- Patch bank tag for B3 instrument. When this instrument is selected,
         we configure Freewheeling to remap several controllers to drawbars. -->
    <declare var="VAR_b3_patchbank_tag" type="int" init="999"/>

    <!-- Mercury mode sets options that I use for performance.
         You can also roll your own special options. -->
    <declare var="VAR_mercurymode" type="char" init="1"/>

    <!-- Variables for breath controller summing with expression pedal -->
    <declare var="VAR_midi_breathcontrol" type="int" init="2"/>
    <declare var="VAR_midi_breathcontrol_val" type="int" init="0"/>
    <declare var="VAR_midi_breathcontrol_hold" type="int" init="0"/>
    <declare var="VAR_midi_holdpedal" type="int" init="64"/>
    <declare var="VAR_midi_exppedal" type="int" init="11"/>
    <declare var="VAR_midi_exppedal_val" type="int" init="0"/>

    <!-- Mercury's startup -->
    <binding input="start-interface"
     output1="show-debug-info" parameters1="show=0"
     output2="set-variable" parameters2="var=VAR_midi_footswitch and value=67"
     output3="set-variable" parameters3="var=VAR_laptopkeymode and value=1"
     output4="set-variable" parameters4="var=VAR_notechan and value=1"
     output5="set-variable" parameters5="var=VAR_noterange and value=48>59"
     output6="patchbrowser-move-to-bank" parameters6="direction=-1"
     output7="browser-select-item" parameters7="browserid=DISPLAY_browser_patch"/>

    <!-- F toggles action of footpedal
    <binding input="key" conditions="VAR_mercurymode=1 and key=f and keydown=1"
     output="toggle-variable" 
     parameters="var=VAR_footpedal_ctrl_num and maxvalue=1"/>
     -->

    <!-- B3 mode MIDI controller remaps -->
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=80"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=70 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=82"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=71 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=83"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=72 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=84"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=73 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=85"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=74 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=81"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=75 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=86"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=76 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=88"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=77 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=89"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=78 and
                                         controlval=controlval"/>

    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=70"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=92 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=71"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=91 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=72"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=80 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=73"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=81 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=74"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=82 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=75"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=21 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=76"
     output="midicontroller" parameters="routethroughpatch=1 and
                                         controlnum=22 and
                                         controlval=controlval"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=77 and controlval=VAR_switch_on"
     output="midiprogramchange" parameters="routethroughpatch=1 and
                                            programval=40"/>
    <binding input="midicontroller" 
     conditions="SYSTEM_cur_patchbank_tag=VAR_b3_patchbank_tag and controlnum=77"
     output="midiprogramchange" parameters="routethroughpatch=1 and
                                            programval=39"/>

    <!-- For my setup, I translate channel aftertouch messages to modwheel 
         messages, adding the pressure to the current modwheel value. 
         This allows me to use aftertouch expressively in conjunction with the
         mod wheel. -->
    <binding input="midichannelpressure" conditions="VAR_mercurymode=1"
     output1="set-variable" parameters1="var=VAR_midi_channelpressure and
                                         value=pressureval"
     output2="midicontroller" parameters2="routethroughpatch=1 and
                                           controlnum=VAR_midi_modwheel and
                                           controlval=VAR_midi_channelpressure+
                                                      VAR_midi_modwheel_val"/>
    <binding input="midicontroller" conditions="VAR_mercurymode=1 and
                                                controlnum=VAR_midi_modwheel"
     output1="set-variable" parameters1="var=VAR_midi_modwheel_val and
                                         value=controlval"
     output2="midicontroller" parameters2="routethroughpatch=1 and
                                           controlnum=VAR_midi_modwheel and
                                           controlval=VAR_midi_channelpressure+
                                                      VAR_midi_modwheel_val"/>

    <!-- DISABLED

         For my setup, I press the hold pedal to hold breath controller values
         constant. I can take a breath without my keyboard playing being
         affected.

    <binding input="midicontroller" 
     conditions="VAR_mercurymode=1 and controlnum=VAR_midi_holdpedal"
     output1="set-variable" parameters1="var=VAR_midi_breathcontrol_hold and
                                         value=controlval"
     output2="midicontroller" 
     parameters2="routethroughpatch=1 and
                  controlnum=VAR_midi_holdpedal and controlval=controlval"/>

      -->

    <!-- For my setup, I sum breath control (CC2) on top of expression pedal 
         (CC11) values. This allows me to set a baseline with my pedal, and
         'breathe' expression on top of it. -->
    <binding input="midicontroller" 
     conditions="VAR_mercurymode=1 and VAR_midi_breathcontrol_hold=0 and
                 controlnum=VAR_midi_breathcontrol"
     output1="set-variable" parameters1="var=VAR_midi_breathcontrol_val and
                                         value=controlval"
     output2="midicontroller" 
     parameters2="routethroughpatch=1 and
                  controlnum=VAR_midi_exppedal and
                  controlval=VAR_midi_exppedal_val+VAR_midi_breathcontrol_val"/>

    <binding input="midicontroller" conditions="VAR_mercurymode=1 and
                                                controlnum=VAR_midi_exppedal"
     output1="set-variable" parameters1="var=VAR_midi_exppedal_val and
                                         value=controlval"
     output2="midicontroller" 
     parameters2="routethroughpatch=1 and
                  controlnum=VAR_midi_exppedal and
                  controlval=VAR_midi_exppedal_val+VAR_midi_breathcontrol_val"/>

    <!-- In my setup, I use a second octave of keys to select loops.
         This allows me to fluidly select a group of loops for fade, stop, start,
         etc -->
    <binding input="midikey"
     conditions="VAR_mercurymode=1 and midichannel=VAR_notechan and 
                 notenum=VAR_noterange+VAR_selectoctave and 
                 keydown=1"
     output="toggle-select-loop"
     parameters="setid=0 and 
                 loopid=notenum-VAR_selectoctave+VAR_loopid_pianostart"/>
  </bindings>

  <graphics>
    <!-- Mercury's patchbanks: -->

    <display interfaceid="0" 
     id="DISPLAY_browser_patch" type="browser" font="main" 
     browsetype="BROWSE_patch" pos="0.0,0.96" 
     xpand="1" xbox="0.1,0.1, 0.9,0.9" xdelay="5.0" show="1">
       <patchbank bypasscc="116" midiport="1" separatechannels="0" suppressprogramchanges="1" patches="patches-receptor-1.xml"/>
       <patchbank bypasscc="116" midiport="1" separatechannels="0" suppressprogramchanges="1" patches="patches-receptor-2.xml"/>
       <patchbank midiport="2" separatechannels="0" patches="patches-synful.xml"/>
       <patchbank bypasscc="116" bypasstime1="60" bypasstime2="10" midiport="1" separatechannels="0" suppressprogramchanges="1" 
        patches="patches-channels.xml"/>
    </display>

<!--
    <display interfaceid="0" 
     id="DISPLAY_browser_patch" type="browser" font="main" 
     browsetype="BROWSE_patch" pos="0.0,0.96" 
     xpand="1" xbox="0.1,0.1, 0.9,0.9" xdelay="5.0" show="1">
       <patchbank midiport="2" separatechannels="1" patches="patches2.xml"/>
       <patchbank midiport="1" suppressprogramchanges="1" separatechannels="0" patches="mercury/patches-piano-strings-small.xml"/>
       <patchbank midiport="3" patches="patches3.xml"/>
       <patchbank midiport="4" patches="patches-b3.xml" tag="999"/>
    </display>
-->
  </graphics>
</interface>
